package interfaceabstract;

import org.junit.Test;

class A{}                 // A动物
class B extends A{}       // B哺乳动物
class C extends B{}       // C猫
class D extends B{}       // D狗

public class InstanceofTest {
	
	@Test
	public void test() {
		// instanceof 属于    不看引用，看对象
		A a = new A();
		B b = new B();
		C c = new C();
		D d = new D();
		A a1 = new B();
		A a2 = new C();
		A a3 = new D();
		B b1 = new C();
		B b2 = new D();
		System.out.println(a instanceof A);  // true
		System.out.println(a instanceof B);  // false
		System.out.println(a instanceof C);  // false
		System.out.println(a instanceof D);  // false
		System.out.println(b instanceof A);  // true
		System.out.println(b instanceof B);  // true
		System.out.println(b instanceof C);  // false
		System.out.println(b instanceof D);  // false
		System.out.println(c instanceof A);  // true
		System.out.println(c instanceof B);  // true
		System.out.println(c instanceof C);  // true
		System.out.println(d instanceof A);  // true
		System.out.println(d instanceof B);  // true
		System.out.println(d instanceof D);  // true
		System.out.println(a1 instanceof A); // true
		System.out.println(a1 instanceof B); // true
		System.out.println(a1 instanceof C); // false
		System.out.println(a1 instanceof D); // false
		System.out.println(a2 instanceof A); // true
		System.out.println(a2 instanceof B); // true
		System.out.println(a2 instanceof C); // true
		System.out.println(a2 instanceof D); // false
		System.out.println(a3 instanceof A); // true
		System.out.println(a3 instanceof B); // true
		System.out.println(a3 instanceof C); // false
		System.out.println(a3 instanceof D); // true
		System.out.println(b1 instanceof A); // true
		System.out.println(b1 instanceof B); // true
		System.out.println(b1 instanceof C); // true
		System.out.println(b1 instanceof D); // false
		System.out.println(b2 instanceof A); // true
		System.out.println(b2 instanceof B); // true
		System.out.println(b2 instanceof C); // false
		System.out.println(b2 instanceof D); // true
	}                       
}
